const { app, BrowserWindow, Menu } = require('electron')
const path = require('path')
const messageHandler = require("./task_book/message_handler");

const createWindow = () => {
    const win = new BrowserWindow({
        width: 1020,
        height: 750,
        resizable: false,
        icon: path.join(__dirname, '/public/taskui.ico'),
        webPreferences: {
            preload: path.join(__dirname, 'preload.js')
        }
    })
    const debug = process.argv[2] === '--dev'
    if (debug) {
        win.loadURL("http://localhost:3000")
    } else {
        Menu.setApplicationMenu(null);
        win.loadFile('./dist/index.html')
    }
}

app.whenReady().then(() => {
    createWindow()
    messageHandler();
    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit()
})